import javax.imageio.IIOException;
import java.io.*;
import java.util.ArrayList;
import java.util.List;

public class Main2 {
    public static void main(String[] args) throws IOException {
        List<Book> list = new ArrayList<>();
        list.add(new Book(1, "a", "z"));
        list.add(new Book(2, "b", "q"));
        list.add(new Book(3, "c", "s"));

        //（2）将这10个对象的成员属性值按类型存入文件中并读出
        ObjectOutputStream outputStream = new ObjectOutputStream(new FileOutputStream("d:/test2.txt"));//对象流写入
        for (Book book : list) {
            outputStream.writeInt(book.getNumber());
            outputStream.writeUTF(book.getName());
            outputStream.writeUTF(book.getAuthor());
        }
        List<Book> list1 = new ArrayList<>();
        ObjectInputStream objectInputStream = new ObjectInputStream(new FileInputStream("d:/test2.txt"));//读数据
        int number;
        String name;
        String author;
        try {
            while (true) {//读出
                number = objectInputStream.readInt();
                name = objectInputStream.readUTF();
                author = objectInputStream.readUTF();
                list1.add(new Book(number, name, author));
            }
        }catch (EOFException e){
            e.printStackTrace();
        }
        }

    }
